/* Problem 4 solution.
	A nearly-brute-force approach to this problem will still yield quick results.
	There are only 810,000 3-digit products to test. However, some simple
	search constraints reduce the number of checks to just over 6000 for 
	products of 3 digit numbers. 4-digit products can be done in 2500 
	iterations--so this is really all luck based. Even algorithms involving 
	some mathematical analysis of palindromic numbers must resort to some
	brute force. Ones I've tested use even more iterations than this.
	*/
#include <stdio.h>

bool is_palindrome(unsigned int n)
{
	unsigned int reverse=0, copy =n;
	while(n > 0)
	{
		reverse*=10;
		reverse+=n%10;
		n/=10;
	}
	
	return (reverse == copy);
	
}

int main()
{
	unsigned int max = 0;
	// Iteration calculation used to help develop good search constraints.
	//unsigned int iter =0;
	
	for(unsigned int i = 999; i >100; i--)
	{
		for(unsigned int j = i; j>100 && j*i > max; j--)
		{
			//iter+=1;
			if (is_palindrome(j*i) && j*i > max)
			{
				max = j*i;
			}
		}
	}
	
	printf("%d\n", max);
	//printf("Iterations: %d\n", iter);
	
	return 0;
}
